import os
import json

# # 获取当前文件所在路径的绝对路径
# cur = os.getcwd()
# print(f'cur==>{cur}')
#
# # 返回上一级目录
# os.chdir(path='..')
# cur = os.getcwd()
# print(f'cur==>{cur}')
#
# # 路径的拼接
# labels_path = os.path.join(cur, 'data/labels.json')
# print(f'labels_path==>{labels_path}')

# 读取json数据
# dict_label = json.load(open(labels_path, 'r', encoding='utf-8'))
# print(f'dict_label==>{dict_label}')

# 设计一个方法：无论在哪个位置调用，都不会报错
abs_path = os.path.abspath(__file__)
print(f'abs_path==>{abs_path}')

# 获取文件的目录名称
dir_name = os.path.dirname(r'D:\workspace\Hongzhizhu\P03_NER\LSTM_CRF')
print(f'dir_name==>{dir_name}')

# 拼接文件目录
labels_path = os.path.join(abs_path, '../../data/labels.json')
print(f'labels_path==>{labels_path}')

# 读取标签json文件中数据
labels_json = json.load(fp=open(labels_path, 'r', encoding='utf-8'))
print(f'labels_json==>{labels_json}')

res = os.walk(os.getcwd())
print(f'res==>{list(res)}')
